package com.jwthhealth_pub.old.sportfitness.view.adapter;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jwthhealth_pub.R;
import com.jwthhealth_pub.common.FontManager;
import com.jwthhealth_pub.old.common.Constant;
import com.jwthhealth_pub.old.common.ImageLoader;
import com.jwthhealth_pub.old.sportfitness.module.SprotCourseModule;
import com.jwthhealth_pub.old.sportfitness.view.SportCourseInfoActivity;
import com.jwthhealth_pub.old.sportfitness.view.SportfitnessCourseListActivity;

import java.util.List;

/**
 * Created by Administrator on 2017/1/4.
 */
public class SportCourseAdapter extends RecyclerView.Adapter {

    private SportfitnessCourseListActivity activity;
    private List<SprotCourseModule.DataBean> list;

    public SportCourseAdapter(SportfitnessCourseListActivity sportfitnessListActivity, List<SprotCourseModule.DataBean> data) {
        this.activity = sportfitnessListActivity;
        this.list = data;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(activity, R.layout.item_sport_course, null);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ViewHolder viewHolder = (ViewHolder) holder;
        final SprotCourseModule.DataBean dataBean = list.get(position);
//        Picasso.with(activity).load(dataBean.getVideo_thumb()).into(viewHolder.img);
        ImageLoader.picasso(dataBean.getVideo_thumb(), viewHolder.img);
        viewHolder.title.setText(dataBean.getName());
        switch (dataBean.getLevel()){
            case "1":
                viewHolder.diffcult.setText(activity.getResources().getString(R.string.sport_diffcult) +
                        " " + activity.getResources().getString(R.string.icon_sport_start) +
                        " " + activity.getResources().getString(R.string.icon_sport_start_o) +
                        " " + activity.getResources().getString(R.string.icon_sport_start_o) +
                        " " + activity.getResources().getString(R.string.icon_sport_start_o));
                break;
            case "2":
                viewHolder.diffcult.setText(activity.getResources().getString(R.string.sport_diffcult) +
                        " " + activity.getResources().getString(R.string.icon_sport_start) +
                        " " + activity.getResources().getString(R.string.icon_sport_start) +
                        " " + activity.getResources().getString(R.string.icon_sport_start_o) +
                        " " + activity.getResources().getString(R.string.icon_sport_start_o));
                break;
            case "3":
                viewHolder.diffcult.setText(activity.getResources().getString(R.string.sport_diffcult) +
                        " " + activity.getResources().getString(R.string.icon_sport_start) +
                        " " + activity.getResources().getString(R.string.icon_sport_start) +
                        " " + activity.getResources().getString(R.string.icon_sport_start) +
                        " " + activity.getResources().getString(R.string.icon_sport_start_o));
                break;
            case "4":
                viewHolder.diffcult.setText(activity.getResources().getString(R.string.sport_diffcult) +
                        " " + activity.getResources().getString(R.string.icon_sport_start) +
                        " " + activity.getResources().getString(R.string.icon_sport_start) +
                        " " + activity.getResources().getString(R.string.icon_sport_start) +
                        " " + activity.getResources().getString(R.string.icon_sport_start));
                break;
            default:break;
        }

        View[] views = new View[]{viewHolder.diffcult};
        FontManager.markAsIconContainer(views);

        viewHolder.summary.setText(dataBean.getSport_body()+" / " + dataBean.getHas_tools() + " / " + dataBean.getTime_long()+ "分钟");
        viewHolder.count.setText(dataBean.getHits() + activity.getResources().getString(R.string.sport_count));

        viewHolder.clickLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(activity, SportCourseInfoActivity.class);
                Bundle bundle = new Bundle();
                bundle.putSerializable(Constant.SPORT_DATA, dataBean);
                intent.putExtras(bundle);
                activity.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder{

        RelativeLayout clickLayout;
        ImageView img;
        TextView title, diffcult, summary, count;

        public ViewHolder(View itemView) {
            super(itemView);
            clickLayout = (RelativeLayout) itemView.findViewById(R.id.click_layout);
            img = (ImageView) itemView.findViewById(R.id.img);
            title = (TextView) itemView.findViewById(R.id.head_title);
            diffcult = (TextView) itemView.findViewById(R.id.diffcult);
            summary = (TextView) itemView.findViewById(R.id.summary);
            count = (TextView) itemView.findViewById(R.id.count);
        }
    }
}
